package com.itheima.demo.Demo06;

public class Ticket1 implements Runnable{
    int ticket=100;
Object s=new Object();
    @Override
    public void run() {

        while (true){
            method();


        }

    }
    public synchronized void method(){
        synchronized (s){
            if(ticket>0){
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(Thread.currentThread().getName()+"正在卖第"+ticket+"张票");
                ticket--;
            }
        }
        }

}
